package when3meet.view;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;

import when3meet.controller.RemoveController;
import when3meet.controller.ReportController;

import javax.swing.ButtonGroup;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;

public class AdminFrame extends JFrame {

	public JPanel contentPane;
	public static AdminFrame adminFrame;
	JLabel doneLabel;
	JRadioButton rdbtnClosedEvent;
	JRadioButton rdbtnOpenEvent;
	JRadioButton rdbtnCompleted, rdbtnUncompleted;
	private JTextField inputField;
	private JLabel removeLabel;
	// ah, public is for test..
	public JButton reportButton;

	/**
	 * Create the frame.
	 */
	private AdminFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 410, 251);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setLocationRelativeTo(null);

		// Select save path
		reportButton = new JButton("Generate Report");
		reportButton.addActionListener(new ReportController());

		doneLabel = new JLabel("DONE!");
		doneLabel.setForeground(Color.PINK);
		doneLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 17));
		doneLabel.setHorizontalAlignment(SwingConstants.CENTER);
		doneLabel.setVisible(false);

		ButtonGroup bg = new ButtonGroup();

		rdbtnOpenEvent = new JRadioButton("Open Event");
		rdbtnClosedEvent = new JRadioButton("Closed Event");
		rdbtnOpenEvent.setSelected(true);
		bg.add(rdbtnClosedEvent);
		bg.add(rdbtnOpenEvent);

		JButton removeButton = new JButton("Remove");
		removeButton.addActionListener(new RemoveController());

		ButtonGroup bg2 = new ButtonGroup();
		rdbtnCompleted = new JRadioButton("Completed");
		rdbtnUncompleted = new JRadioButton("Uncompleted");
		rdbtnUncompleted.setSelected(true);
		bg2.add(rdbtnCompleted);
		bg2.add(rdbtnUncompleted);

		inputField = new JTextField();
		inputField.setForeground(Color.LIGHT_GRAY);
		inputField.setHorizontalAlignment(SwingConstants.CENTER);
		inputField.setFont(new Font("Tahoma", Font.PLAIN, 14));
		inputField.setText("Days old or event Id");
		inputField.setColumns(10);

		removeLabel = new JLabel("Events affected");
		removeLabel.setForeground(new Color(0, 0, 0));
		removeLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
		removeLabel.setHorizontalAlignment(SwingConstants.CENTER);
		removeLabel.setVisible(false);

		// Layout for the frame
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane
				.setHorizontalGroup(gl_contentPane
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_contentPane
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_contentPane
														.createParallelGroup(Alignment.LEADING)
														.addComponent(removeLabel, GroupLayout.DEFAULT_SIZE, 344,
																Short.MAX_VALUE)
														.addGroup(
																gl_contentPane
																		.createSequentialGroup()
																		.addGroup(
																				gl_contentPane
																						.createParallelGroup(
																								Alignment.LEADING)
																						.addGroup(
																								gl_contentPane
																										.createSequentialGroup()
																										.addGroup(
																												gl_contentPane
																														.createParallelGroup(
																																Alignment.TRAILING,
																																false)
																														.addComponent(
																																removeButton,
																																Alignment.LEADING,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																Short.MAX_VALUE)
																														.addComponent(
																																reportButton,
																																Alignment.LEADING,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																Short.MAX_VALUE))
																										.addPreferredGap(
																												ComponentPlacement.UNRELATED)
																										.addGroup(
																												gl_contentPane
																														.createParallelGroup(
																																Alignment.LEADING)
																														.addGroup(
																																gl_contentPane
																																		.createSequentialGroup()
																																		.addGroup(
																																				gl_contentPane
																																						.createParallelGroup(
																																								Alignment.LEADING)
																																						.addComponent(
																																								rdbtnUncompleted)
																																						.addComponent(
																																								rdbtnCompleted))
																																		.addPreferredGap(
																																				ComponentPlacement.RELATED)
																																		.addComponent(
																																				inputField,
																																				GroupLayout.DEFAULT_SIZE,
																																				166,
																																				Short.MAX_VALUE))
																														.addGroup(
																																gl_contentPane
																																		.createSequentialGroup()
																																		.addGroup(
																																				gl_contentPane
																																						.createParallelGroup(
																																								Alignment.LEADING)
																																						.addComponent(
																																								rdbtnClosedEvent)
																																						.addComponent(
																																								rdbtnOpenEvent))
																																		.addPreferredGap(
																																				ComponentPlacement.RELATED,
																																				166,
																																				Short.MAX_VALUE))))
																						.addComponent(
																								doneLabel,
																								GroupLayout.PREFERRED_SIZE,
																								344,
																								GroupLayout.PREFERRED_SIZE))
																		.addContainerGap()))));
		gl_contentPane
				.setVerticalGroup(gl_contentPane
						.createParallelGroup(Alignment.TRAILING)
						.addGroup(
								gl_contentPane
										.createSequentialGroup()
										.addGap(11)
										.addGroup(
												gl_contentPane
														.createParallelGroup(Alignment.LEADING)
														.addGroup(
																gl_contentPane
																		.createSequentialGroup()
																		.addComponent(reportButton,
																				GroupLayout.PREFERRED_SIZE, 42,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(25)
																		.addComponent(removeButton,
																				GroupLayout.PREFERRED_SIZE, 41,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPane
																		.createSequentialGroup()
																		.addComponent(rdbtnOpenEvent)
																		.addPreferredGap(ComponentPlacement.RELATED)
																		.addComponent(rdbtnClosedEvent)
																		.addGap(16)
																		.addGroup(
																				gl_contentPane
																						.createParallelGroup(
																								Alignment.LEADING,
																								false)
																						.addComponent(
																								inputField,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE)
																						.addGroup(
																								gl_contentPane
																										.createSequentialGroup()
																										.addComponent(
																												rdbtnUncompleted)
																										.addPreferredGap(
																												ComponentPlacement.UNRELATED)
																										.addComponent(
																												rdbtnCompleted)))))
										.addGap(18)
										.addComponent(doneLabel)
										.addPreferredGap(ComponentPlacement.RELATED)
										.addComponent(removeLabel, GroupLayout.PREFERRED_SIZE, 25,
												GroupLayout.PREFERRED_SIZE).addContainerGap()));
		contentPane.setLayout(gl_contentPane);
	}

	public static AdminFrame getInstance() {
		if (adminFrame == null) {
			adminFrame = new AdminFrame();
		} else {

		}
		return adminFrame;
	}

	public JLabel getDoneLabel() {
		return doneLabel;
	}

	public JRadioButton getRdbtnClosedEvent() {
		return rdbtnClosedEvent;
	}

	public JRadioButton getRdbtnOpenEvent() {
		return rdbtnOpenEvent;
	}

	public JTextField getInput() {
		return inputField;
	}

	public JRadioButton getRdbtnCompleted() {
		return rdbtnCompleted;
	}

	public JLabel getRemoveLabel() {
		return removeLabel;
	}
}
